import 'dart:convert';
import 'package:flutter/material.dart';

import 'package:state_flutter/api/axios.dart';

class UserInfo extends StatefulWidget {
  UserInfo({Key key}) : super(key: key);

  @override
  _UserInfoState createState() => _UserInfoState();
}

class _UserInfoState extends State<UserInfo> {

  @override
  void initState() { 
    super.initState();

    var res = getData();
    
    Map userInfo = {
      'username': 'snake皮',
      'age': 20
    };
    String userInfoString = '{"username": "snake皮", "age": 20}';

    print(json.encode(userInfo));     //Map 转 JSON字符串
    print(json.decode(userInfoString));   //JSON字符串 转 Map
  }

  @override
  Widget build(BuildContext context) {
    return Drawer(
      child: Column(
        children: <Widget>[
          Row(
            children: <Widget>[
              Expanded(
                child: UserAccountsDrawerHeader(
                  accountName: Text('snake皮'),
                  accountEmail: Text('1287414150@qq.com'),
                  currentAccountPicture: CircleAvatar(
                    backgroundImage: AssetImage(
                      "lib/common/images/2.0x/02.jpg"
                    ),
                  ),
                  otherAccountsPictures: <Widget>[
                    IconButton(
                      color: Colors.white,
                      icon: Icon(Icons.settings),
                      onPressed: (){
                        Navigator.of(context).pop();
                        Navigator.pushNamed(context, '/card');
                      },
                    )
                  ],
                  decoration: BoxDecoration(
                    image: DecorationImage(
                      fit: BoxFit.cover,
                      image: NetworkImage(
                        "https://c-ssl.duitang.com/uploads/item/201711/26/20171126195857_MtFYk.thumb.700_0.jpeg"
                      )
                    )
                  ),
                ),
              )
            ],
          ),
        ],
      )
    );
  }
}
